#include <stdio.h>
#include <stdlib.h>

int count_1(int x) {	//统计每个数中1出现的个数
	int sum = 0;
	while (x) {
		sum += (x%10 == 1);
		x /= 10;
	}
	return sum;
}

int count_1_n(int n) {
	int i, sum = 0;
	for (i = 1; i <= n; i++) {
		sum += count_1(i);
	}
	return sum;
}

int main()
{
	printf("count 1 from 1 to n:%d\n",count_1_n(13));
	return 0;
}